#include<stdio.h>
#include<stdlib.h>
typedef struct Student {                                             //定义结构体Student
	int num;
	float score;
	struct Student* next;
}Student;
void input(Student* stu, int n)
{
	int i;
	Student* p;
	for (p = stu, i = 0; p < stu + n; p++, i++)
	{
		scanf("%d%f", &p->num, &p->score);
		if (i == n - 1)
			p->next = NULL;
		else
			p->next = &stu[i + 1];
	}
}
Student *fun(Student* s1, Student* s2, int m, int n)
{
	Student* p=s1, * q, tmp;
	while(s1->next!=NULL)
	{
		s1=s1->next;
	}
	s1->next=s2;
	for (p ; p != NULL; p = p->next)
	{
		for (q = p; q != NULL; q = q->next)
		{
			if (p->num > q->num)
			{
				tmp.num = p->num;
				p->num = q->num;
				q->num = tmp.num;
				tmp.score = p->score;
				p->score = q->score;
				q->score = tmp.score;
			}
		}
	}
	//for(p=)
	return s1;
}
void print(Student *stu)
{
    Student *p;
    for(p=stu;p!=NULL;p=p->next)
    {
        printf("%d %.0f\n",p->num,p->score);
    }
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    Student *a=(Student*)malloc((m+n)*sizeof(Student));
    Student *b=(Student*)malloc(m*sizeof(Student));
    input(a,n);
    input(b,m);
    fun(a,b,m,n);
    print(a);
	return 0;
}